#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

int main() {
    int year = 0, month = 0;
    while (~scanf("%d %d", &year, &month))
    {
        if (year % 4 == 0 && year / 100 != 0 || year % 400 == 0)
        {
            if (month == 2)
                month = 29;
            else if (month == 4 || month == 6 || month == 9 || month == 11)
                month = 30;
            else month = 31;
        }
        else
        {
            if (month == 2)
                month = 28;
            else if (month == 4 || month == 6 || month == 9 || month == 11)
                month = 30;
            else month = 31;

        }
        printf("%d\n", month);
    }
    return 0;
}















